package com.dferreira.axil.data;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import com.dferreira.axil.model.Servico;

@RequestScoped
public class ListaDeServicos {

    @Inject
    private RepositorioDeServicos repositorioDeServicos;

    private List<Servico> servicos;

    @Produces
    @Named
    public List<Servico> getServicos() {
        return servicos;
    }

    public void quandoAlterarListaDeServicos(@Observes(notifyObserver = Reception.IF_EXISTS) final Servico servico) {
    	recuperarServicos();
    }

    @PostConstruct
    public void recuperarServicos() {
        servicos = repositorioDeServicos.findAllOrderedByName();
    }
}
